
#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
# @file   : pwd_strength.py
# @author : weichy
# @date   : 2019/01/05
# @version: 1.0
# @desc   :  1.0通过计算机程序模拟掷骰子，一个骰子
                2.0模拟投2颗骰子
                3.0使用绘图工具可视化，可视化抛掷2个骰子的结果
            
'''



import random   
import matplotlib.pyplot as plt

def roll_dice():
    '''
    模拟掷骰子
    '''
    roll = random.randint(1,6)
    return roll

def main():
    total_times = 10000


    # 初始化列表[00000]

    result_list = [0] * 11
    # 初始化点数列表
    roll_list = list(range(2,13))
    roll_dict = dict(zip(roll_list,result_list))

    #记录第一个骰子的结果
    roll1_list = []
    roll2_list = []

    for i in range(total_times):
        roll_one = roll_dice()
        roll_two = roll_dice()

        roll1_list.append(roll_one)
        roll2_list.append(roll_two)
        for j in range(2,13):
            if (roll_one + roll_two) == j:
                roll_dict[j] += 1
    for i,result in roll_dict.items():
        print('点数{}的次数：{}，频率为：{}。'.format(i,result,result/total_times))

    # 数据可视化
    x = range(1,total_times+1)
    plt.scatter(x,roll1_list,c='red',alpha = 0.5)
    plt.scatter(x,roll2_list,c='green',alpha = 0.5)
    plt.show()

    
  


if __name__ == '__main__':
    main()
